#include "../head.h"


int main()
{
    // 1.创建套接字
    int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
    // 2.创建结构体
    struct sockaddr_in client_addr;
    client_addr.sin_family = AF_INET;
    client_addr.sin_port = htons(6153);
    client_addr.sin_addr.s_addr = inet_addr("192.168.47.198");
        
    int len = sizeof(struct sockaddr_in);
    // 3.发送数据
    while (1)
    {
        char buf[1024] = {0};
        printf("请输入数据：");
        scanf("%s", buf);
        sendto(sockfd, buf, strlen(buf), 0, (struct sockaddr *)&client_addr, sizeof(struct sockaddr_in));
        if (strcmp(buf, "exit") == 0)
        {
            break;
        }
        memset(buf, 0, sizeof(buf));
        recvfrom(sockfd, buf, sizeof(buf), 0, (struct sockaddr *)&client_addr, &len);   
        printf("服务器回复：%s\n", buf); 
    }
    close(sockfd);


    return 0;
}